/*
 * @Author: long-xinyu2 2192763423@qq.com
 * @Date: 2025-03-11 18:46:10
 * @LastEditors: long-xinyu2 2192763423@qq.com
 * @LastEditTime: 2025-03-25 10:17:25
 * @FilePath: \algorithm\algorithm-training\ICPC-Code-Template-in-Latex-master\基础算法\离散化.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//离散化求区间和
const int N = 300010;

vector<int>arr;
vector<pair<int,int>>qu;
vector<pair<int,int>>quary;
int a[N];

int find1(int x)//arr下标从0开始，数组下标从1开始
{
    int left = 0;
    int right = arr.size()-1;
    while(left<right)
    {
        int mid = (left + right)>>1;
        if(arr[mid]<x) left = mid + 1;
        else right = mid;
    }
    return left + 1;
}
int find2(int x)//arr下标从1开始，数组下标从1开始，使用前先将arrpush一个最小负数（-1）
{
    return lower_bound(arr.begin(), arr.end(), x) - arr.begin();
}


int main()
{
    int n,m;
    cin >> n >> m;
    for(int i = 1;i<=n;i++)
    {
        int a,b;
        cin >> a >> b;
        qu.push_back({a,b});
        arr.push_back(a);
    }
    for(int i = 1;i<=m;i++)
    {
        int a,b;
        cin >> a >> b;
        arr.push_back(a);
        arr.push_back(b);
        quary.push_back({a,b});
    }
    sort(arr.begin(),arr.end());
    arr.erase(unique(arr.begin(),arr.end()),arr.end());
    for(auto x : qu)
    {
        int p = find1(x.first);
        a[p]+=x.second;
    }
    for(int i = 1;i<=arr.size();i++)
    {
        a[i] += a[i-1]; 
    }
    for(auto x :quary)
    {
        int fi = find1(x.first);
        int se = find1(x.second);
        cout<<a[se] - a[fi-1]<<endl;
    }
    return 0;
}